﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MountainORocks
{
    class Smoke : Particle
    {
        
        public Smoke(Vector2 location,
            Vector2 trajectory,
            float r,
            float b,
            float g,
            float a,
            float size,
            float rotation):base("Smoke")
        {
            this.location = location;
            this.trajectory = trajectory;
            this.r = r;
            this.b = b;
            this.g = g;
            this.a = a;
            this.size = size;
            this.Exists = true;
            this.rotation = rotation;
            this.frame = 1.0f;
        }

        public override void Update(float gameTime)
        {
            if (frame < 0.5f)
            {
                if (trajectory.X < -10.0f) trajectory.X += gameTime * 500.0f;
                if (trajectory.X < -10.0f) trajectory.X += gameTime * 150.0f;
                if (trajectory.X > 10.0f) trajectory.X -= gameTime * 150.0f;
            }
            base.Update(gameTime);
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Microsoft.Xna.Framework.Graphics.Texture2D spriteText)
        {
            Rectangle sRect = new Rectangle(0, 0, 128, 128);

            float frameAlpha;

            if (frame > 0.9f)
                frameAlpha = (1.0f - frame) * 10.0f;
            else
                frameAlpha = (frame / 0.9f);

            spriteBatch.Draw(spriteText,
                Location,
                sRect,
                new Color(
                    new Vector4(frame * r,
                                frame * g,
                                frame * b,
                                a * frameAlpha)
                                ),
                rotation,
                new Vector2(64.0f,64.0f),
                size + (1.0f - frame),
                SpriteEffects.None,
                1.0f);

            
            base.Draw(spriteBatch, spriteText);
        }
    }
}
